import {get,post,put,setTokens} from "../httpx";
import {ProblemApi} from "../urls";


const JAVA_DEFAULT =
`public class Main{
    
    public static void main(String[] args){
        
    }
    
}`

const CPP_DEFAULT =
  `#include<iostream>
using namespace std;
int main(){
  
   return 0;
}`

const GO_DEFAULT =
`package main

import "fmt"

func main(){

}`


/**
 * 获取默认代码
 * @param language 语言
 * @param id 题目ID
 */
const getDefaultCode = (language,id)=>{
    if (language === 'java'){
        return JAVA_DEFAULT;
    }else if (language === 'cpp'){
        return CPP_DEFAULT;
    }else {
        return GO_DEFAULT;
    }
}

const getAll = () => get(ProblemApi.getAll,{},true)

const getById = id => get(ProblemApi.getProblemById, {value:id} , true)

const getHot = ()=>get(ProblemApi.getHot,{} , true)

const getIO = id=>get(ProblemApi.getIO,{value:id})

const addOrUpdate = data => post(ProblemApi.addOrUpdate,data)

const getLanguageNameByCode = (code)=>{
    if (code == 1){
        return 'Java'
    }else if (code == 2){
        return 'Cpp'
    }else {
        return 'Go'
    }
}

export const Problem = {
    getDefaultCode,getAll,getById,getHot,getLanguageNameByCode,getIO,addOrUpdate
}
